package ink.lovejinhu.leetcode;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @Author: jin
 * @Date: 2021/9/10 8:42
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_0884 {
    /**
     * 在两句话中只出现一次的就是不常见的字符串
     *
     * @param s1
     * @param s2
     * @return
     */
    public String[] uncommonFromSentences(String s1, String s2) {
        String s3 = s1 + " " + s2;
        String[] s = s3.split(" ");
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < s.length; i++) {
            if (map.containsKey(s[i])) {
                map.put(s[i], map.get(s[i]) + 1);
            } else {
                map.put(s[i], 1);
            }
        }
        ArrayList<String> res = new ArrayList<>();
        for (String temp : map.keySet()
        ) {
            Integer integer = map.get(temp);
            if (integer.equals(1)) {
                res.add(temp);
            }
        }
        String[] resStr = new String[res.size()];
        for (int i = 0; i < res.size(); i++) {
            resStr[i] = res.get(i);

        }
        return resStr;
    }
}
